﻿using UnityEngine.UI;
using UnityEngine;
using System.Collections;
using System;

/// <summary>
/// 通用工具
/// </summary>
public static class Utils
{
    public static void LogWithColor(string text = "", string title = "", string color = "white")
    {
        Debug.Log( string.Format("<color={0}>{1}</color>{2}", color, title, text) );
    }

    public static void SafeActionCallback(Action callback)
    {
        if (callback != null) { callback(); }
    }

    public static bool FloatEqual(float a, float b)
    {
        return Mathf.Abs(a - b) < 0.001f;
    }

    /// <summary>
    /// N秒后回调
    /// </summary>
    public static IEnumerator CallbackWithSecond(float second, Action callback)
    {
        yield return new WaitForSeconds(second);

        if (callback != null) { callback.Invoke(); };
    }

    /// <summary>
    /// 下次固定帧更新时回调
    /// </summary>
    public static IEnumerator CallbackWithFixedUpdate(Action callback)
    {
        yield return new WaitForFixedUpdate();

        if (callback != null) { callback.Invoke(); } ;
    }
}
